﻿using System;
using System.Collections.Generic;

using BizElements.BusinessLayer;

namespace BizElements.Web
{
    /// <summary>
    /// A component which displays a collection of <see cref="ICommand"/> objects in UI.
    /// </summary>
    public interface ICommandDisplay
    {
        #region Properties.

        /// <summary>
        /// Gets or sets command hierarchy which defines how <see cref="ICommand"/> objects are grouped and displayed in UI.
        /// </summary>
        /// <remarks>Implementations should ignore entries for commands which are not present in the <see cref="Commands"/> collection.</remarks>
        CommandGroupStyle CommandHierarchy { get; set; }

        /// <summary>
        /// Gets or sets a collection of commands which are to be displayed in the <b>CommandToolBar</b>.
        /// </summary>
        /// <remarks>Commands which are not defined in the <see cref="CommandHierarchy"/> should not be displayed.</remarks>
        IList<ICommand> Commands { get; set; }

        /// <summary>
        /// Gets or sets the actor which is using the displayed commands. Nullable.
        /// </summary>
        /// <remarks>When set, the implementating class should run security checks to see which of the commands 
        /// provided in the <see cref="Commands"/> collection are available to the actor.</remarks>
        IActor Actor { get; set; }

        /// <summary>
        /// Gets or sets the optional <see cref="IMessageFormatter"/> object used to format values and messages
        /// in conformity with the standards of the <see cref="Actor"/>'s culture.
        /// </summary>
        IMessageFormatter Formatter { get; set; }

        #endregion

        #region Methods.

        /// <summary>
        /// Gets <see cref="ICommandDisplay"/> settings.
        /// </summary>
        /// <returns>A collection of key-value property pairs guaranteed to work only with 
        /// the <see cref="ICommandDisplay"/> implementation which created it.</returns>
        IDictionary<string, object> GetSettings();

        /// <summary>
        /// Applies <see cref="ICommandDisplay"/> settings to the current instance.
        /// </summary>
        /// <param name="settings">Settings collection which was created by the same or compatibile
        /// <see cref="ICommandDisplay"/> implementation as the current instance.</param>
        void ApplySettings(IDictionary<string, object> settings);

        #endregion
    }
}